<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function pause(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    
    while (true) {
         now = new Date();
         if (now.getTime() > exitTime)
             return;
    }
}
var xhr;
function creatXhr(){
	if(window.ActiveXObject){
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xhr = new XMLHttpRequest();
	}
}
function test1(i){
	if(i==undefined){
		var i = 0;
	}
		id1=setTimeout("getHello2("+i+")",1000);	
}
function getHello2(i){
	var totalNum = 0;
	var num = 1;
	totalNum =  i + num;
	creatXhr();
	var quertString = "i="+i;
	xhr.onreadystatechange = callback;
	xhr.open("POST","/TEST_Project/TestServlet",true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(quertString);
	if(totalNum==10){
		cleartTimeout(id);
		cleartTimeout(id1);
	}else{
		id=setTimeout("test1("+totalNum+")",1000);
	}
}
function callback(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var restTxt = xhr.responseText;
			document.getElementById("resultLayer").innerHTML = restTxt;
		}else{
			alert("요청에 대한 처리를 하지 못햇습니다.: "+xhr.status);
		}
	}
}
</script>
</head>
<body>
<button onclick="test1()">클릭</button>
<div id="resultLayer"></div>
</body>
</html>